"use strict";
const path = require("path");

function resolve(dir) {
  return path.join(__dirname, dir);
}
const name = process.env.VUE_APP_TITLE;
const publicPath = process.env.VUE_APP_PUBLIC_PATH;
const baseUrl = process.env.VUE_APP_BASE_API || 'http://test.future-better.com';
const port =
  process.env.port ||
  process.env.npm_config_port ||
  process.env.VUE_APP_PORT ||
  9500;
module.exports = {
  publicPath,
  outputDir: "dist",
  assetsDir: "static",
  lintOnSave: process.env.NODE_ENV === "development",
  productionSourceMap: false,
  devServer: {
    port,
    open: false,
    proxy: {
      "/api": {
        target: baseUrl,
        ws: true,
        changeOrigin: true,
        pathRewrite: {
          '': ''
        }
      },
    },
    overlay: {
      warnings: false,
      errors: true
    },
  },
  configureWebpack: {
    name,
    resolve: {
      alias: {
        '@': resolve('src')
      }
    }
  },
  pluginOptions: {
    "style-resources-loader": {
      preProcessor: "less",
      patterns: [resolve("src/style/index.less")]
    }
  },
  chainWebpack(config) {
    config.plugin("preload").tap(() => [
      {
        rel: "preload",
        fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
        include: "initial"
      }
    ]);
    config.plugins.delete("prefetch");
    config.module
      .rule("svg")
      .exclude.add(resolve("src/icons"))
      .end();
    config.module
      .rule("icons")
      .test(/\.svg$/)
      .include.add(resolve("src/icons"))
      .end()
      .use("svg-sprite-loader")
      .loader("svg-sprite-loader")
      .options({
        symbolId: "icon-[name]"
      })
      .end();
  }
};